package com.jp.fm.service;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

import com.jp.fm.EasyMockParent;
import com.jp.fm.dao.AccountDao;
import com.jp.fm.dao.TransactionDao;
import com.jp.fm.data.Account;
import com.jp.fm.data.Account.AccountBalance;

public class AccountServiceTest extends EasyMockParent {
	private AccountService accountService = null;

	private HttpServletRequest mockRequest = null;
	private TransactionDao mockTransactionDao = null;
	private AccountDao mockAccountDao = null;

	@BeforeClass
	public static void setUpBeforeClass() throws Exception {
	}

	@AfterClass
	public static void tearDownAfterClass() throws Exception {
	}

	@Before
	public void setUp() throws Exception {
		super.setUp();

		accountService = new AccountService();
	}

	@After
	public void tearDown() throws Exception {
		super.tearDown();
	}

	@Test
	public final void testRemoveHiddenAccountsOneRemoved() {

		List<Account> accounts = new ArrayList<Account>();
		accounts.add(new Account(null, "test1", null, null, null,
				new AccountBalance(null, Float.valueOf("5000"), null), 0));
		accounts.add(new Account(null, "test2", null, null, null,
				new AccountBalance(null, Float.valueOf("200"), null), 1));

		accounts.get(0).setHidden(true);

		replayMocks();

		List<Account> updatedAccountsList = accountService
				.removeHiddenAccounts(accounts);

		assertNotNull(updatedAccountsList);
		assertEquals(1, updatedAccountsList.size());
	}

	@Test
	public final void testRemoveHiddenAccountsZeroRemoved() {

		List<Account> accounts = new ArrayList<Account>();
		accounts.add(new Account(null, "test1", null, null, null,
				new AccountBalance(null, Float.valueOf("5000"), null), 0));
		accounts.add(new Account(null, "test2", null, null, null,
				new AccountBalance(null, Float.valueOf("200"), null), 1));

		replayMocks();

		List<Account> updatedAccountsList = accountService
				.removeHiddenAccounts(accounts);

		assertNotNull(updatedAccountsList);
		assertEquals(accounts.size(), updatedAccountsList.size());

	}

}
